package cn.shopifymall.studying.classloader;


import cn.shopifymall.studying.spi.SalaryCalService;

import java.util.Iterator;
import java.util.ServiceLoader;

/**
 * SPI，加自定义类加载器
 *
 * @Author 孤风雪影
 * @Email gitee.com/efairy520
 * @Date 2025/1/16 10:23
 * @Version 1.0
 */
public class OADemo04 {
    public static void main(String[] args) throws Exception {
        Double money = 2000.0;
        while (true) {
            SalaryJarLoader salaryJarLoader = new SalaryJarLoader("D:\\kit1\\swift-kit.jar");
            ServiceLoader<SalaryCalService> services = ServiceLoader.load(SalaryCalService.class, salaryJarLoader);
            Iterator<SalaryCalService> iterator = services.iterator();
            if (iterator.hasNext()) {
                SalaryCalService service1 = iterator.next();
                System.out.println("原本的工资 = " + service1.cal(money));

            }

            SalaryJarLoader salaryJarLoader2 = new SalaryJarLoader("D:\\kit2\\swift-kit.jar");
            ServiceLoader<SalaryCalService> services2 = ServiceLoader.load(SalaryCalService.class, salaryJarLoader2);
            Iterator<SalaryCalService> iterator2 = services2.iterator();
            if (iterator2.hasNext()) {
                SalaryCalService service2 = iterator2.next();
                System.out.println("修改后的工资 = " + service2.cal(money));

            }

            Thread.sleep(1000);
        }
    }
}
